package com.jacobson.huobi.websocket

import com.jacobson.core.widget.storage.GlobalStorage
import com.jacobson.huobi.common.constants.CommonConstant
import com.jacobson.huobi.common.expansion.toJson
import com.jacobson.huobi.entities.ActionEnum
import com.jacobson.huobi.entities.websocket.CommitAccessTokenAction
import com.jacobson.huobi.entities.websocket.HeartbeatAction
import com.jacobson.huobi.entities.websocket.Protocol
import com.jacobson.huobi.entities.websocket.RefreshSymbolAction

object ProtocolFactory {
    fun ofHeartbeat(): Protocol {
        return Protocol(ActionEnum.HEARTBEAT.value, HeartbeatAction().toJson())
    }

    fun ofRefreshSymbolAction(market: String, volumeLevel: String): Protocol {
        return Protocol(
            ActionEnum.REFRESH_SYMBOL.value,
            RefreshSymbolAction(market = market, volume_level = volumeLevel).toJson()
        )
    }

    /**
     * 订阅
     */
    fun ofSubscribe(): Protocol {
        return Protocol(ActionEnum.SUBSCRIBE.value, RefreshSymbolAction(market = GlobalStorage.get(CommonConstant.KEY_SEL_MARKET).toString(),
            volume_level = GlobalStorage.get(CommonConstant.KEY_SEL_VOLUME_LEVEL).toString()).toJson())
    }

    /**
     * 取消订阅
     */
    fun ofUnSubscribe(): Protocol {
        return Protocol(ActionEnum.UN_SUBSCRIBE.value, HeartbeatAction().toJson())
    }

    /**
     * 提交token
     */
    fun ofCommitAccessToken(accessToken: String): Protocol {
        return Protocol(ActionEnum.COMMIT_ACCESS_TOKEN.value, CommitAccessTokenAction(access_token = accessToken).toJson())
    }
}